package com.Web.Student;

import com.DAO.Impl.ScheduleDAOImpl;
import com.DAO.Impl.StudentDAOImpl;
import com.entity.Student;
import com.google.gson.Gson;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;

/**
 * @author 20x
 * @date 2024 - 12 -16
 **/
@WebServlet("/ListStuAboutClass")
public class ListStuAboutClass extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        Gson gson = new Gson();

        String id = req.getParameter("id");
        String time = req.getParameter("time");
        List<Student> list = new ScheduleDAOImpl().queryStudentByStuId(id,time);
        List<Student> studentList = new StudentDAOImpl().ListStudent();

        HashMap<String, Object> map = new HashMap<>();
        map.put("studentList", studentList);
        map.put("list", list);

        out.write(gson.toJson(map));
    }
}
